﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;
using System.Collections.Generic;

namespace OestsServer.Handlers.OESPHandlers
{
    public class GetExamPaperHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.GetExamPaperByStudent;

        public override void Execute(OESPClientChannel client, Request requestPacket)
        {
            base.Execute(client, requestPacket);

            int paperId = int.Parse(requestPacket.DataStr);
            Paper paper = PaperDAL.GetPaperByID(paperId);

            ResponsePacket.DataObject = paper;
            client.Send(ResponsePacket);
        }
    }

    public class StudentExamDataTableHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.StudentExamDataTable;

        public override void Execute(OESPClientChannel client, Request requestPacket)
        {
            base.Execute(client, requestPacket);

            List<ExamData> data = StudentExamDAL.GetExamDatas();

            ResponsePacket.DataObject = data;
            client.Send(ResponsePacket);
        }
    }



    public class UpdateExamDataTableHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.UpdateExamDataByID;

        public override void Execute(OESPClientChannel client, Request requestPacket)
        {
            base.Execute(client, requestPacket);

            int examId = int.Parse(requestPacket.DataStr);

            List<ExamData> data = StudentExamDAL.GetExamDatasByID(examId);

            ResponsePacket.DataObject = data;
            client.Send(ResponsePacket);
        }
    }

    public class StudentTheoryLogHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey => PacketKey.StudentTheoryLog;

        public override void Execute(OESPClientChannel client, Request requestPacket)
        {
            base.Execute(client, requestPacket);

            DP<int, int> data = JsonMapper.ToObject<DP<int, int>>(requestPacket.DataStr);


            ExamData examData = StudentExamDAL.StudentGetTheoryExamLog(data);

            ResponsePacket.DataObject = examData;
            client.Send(ResponsePacket);
        }
    }

}
